﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.Logging;
using System.Reflection;
using System.Resources;
using MayfairFramework.Common.DI;

namespace MayfairFramework.Common.Resource
{
    /// <summary>
    /// 
    /// </summary>
    public static class ResourceManager
    {
        /// <summary>
        /// 
        /// </summary>
        private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// 
        /// </summary>
        private static IList<System.Resources.ResourceManager> list = new List<System.Resources.ResourceManager>();

        /// <summary>
        /// 
        /// </summary>
        static ResourceManager()
        {
            list.Add(MessageProperties.ResourceManager);
            // DIContainer で独自のリソースを追加する
            //list.Add(DIContainerFactory.GetDIContainer().GetObject<System.Resources.ResourceManager>("hoge"));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetString(string key)
        {
            log.Debug(key + "を取得依頼されました。");
            foreach (var resource in list)
            {
                string value = resource.GetString(key);
                if (value != null)
                {
                    return value;
                }
            }
            throw new ArgumentException("リソースが見つかりません。キー : " + key);
        }
    }
}
